<template>
  <!-- <el-container class="home-container">
    <el-header>
      <div>
        <img src="@/assets/img/common/logo.jpg" alt="">
        <h3>电商后台管理系统</h3>
      </div>
      <el-button type="primary" round @click="outClick">退出</el-button>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu background-color="#545c64" text-color="#fff" active-text-color="#ffd04b">
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>一级菜单</span>
            </template>
            <el-menu-item index="1-3">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>二级菜单</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>Main</el-main>
    </el-container>
  </el-container> -->
  <!-- 侧边栏导航栏区域 -->
  <el-container style="height: 100%">
    <el-aside :width="collapse ? '64px' : '200px'">
      <el-menu background-color="#333744" :unique-opened="true" :collapse-transition="false" :collapse="collapse"
        text-color="#fff" active-text-color="#007cff" :router="true" :default-active="$route.path">
        <el-submenu :index="item.id + ''" v-for="(item, index) in menuList">
          <template slot="title">
            <i :class="iconList[index]"></i>
            <span>{{item.authName}}</span>
          </template>
          <el-menu-item :index="'/' + childItem.path" v-for="childItem in item.children">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>{{childItem.authName}}</span>
            </template>
          </el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <div class="info">
          <div class="icon-open" @click="isCollapse">
            <i class="el-icon-open"></i>
          </div>
          <h3>后台管理系统</h3>
        </div>
        <div class="portrait">
          <img src="@/assets/img/common/logo.jpg" alt="">
          <el-button type="primary" round @click="outClick">退出</el-button>
        </div>
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { request } from '@/network/request'
export default {
  name: "Home",
  created() {
    this.getMenuList()
  },
  data() {
    return {
      menuList: [],
      iconList: ['el-icon-user-solid', 'el-icon-s-tools', 'el-icon-s-goods', 'el-icon-s-shop', 'el-icon-s-data'],
      collapse: false
    }
  },
  methods: {
    outClick() {
      window.sessionStorage.clear()
      this.$router.replace('/login')
    },
    async getMenuList() {
      // 请求菜单列表
      const { data: res } = await request({
        method: 'get',
        url: '/menus'
      })
      console.log(res.data);
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.menuList = res.data
    },
    isCollapse() {
      this.collapse = !this.collapse
    }
  }
}
</script>

<style lang='less' scoped>
.el-aside {
  background-color: #333744;
}

.el-header {
  background-color: #333744;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .info {
    display: flex;
    align-items: center;
  }

  .icon-open {
    font-size: 32px;
    margin-right: 24px;
    cursor: pointer;
    color: #fff;
  }

  h3 {
    display: inline-block;
    font-size: 28px;
    font-weight: 400;
    color: #fff;
    text-shadow: 0 2px 2px rgba(100, 100, 100, .4);
  }

  .portrait {
    display: flex;
    align-items: center;

    img {
      width: 50px;
      height: 50px;
      border-radius: 50%;
      margin-right: 15px;
    }
  }
}

.el-main {
  background-color: #eaedf1;
}

.el-menu {
  border: 0;
}

.el-menu-item:hover {
  background-color: #007cff !important;
  color: #fff;
}

.el-submenu:hover {
  background-color: #007cff !important;
}
</style>